package com.jh3502.helper.function.me;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.jh3502.helper.BuildConfig;
import com.jh3502.helper.R;
import com.jh3502.helper.base.BaseFragment;
import com.jh3502.helper.utils.SpHelper;
import com.jh3502.helper.view.NumAnim;
import com.jh3502.helper.view.RoundImageView;

import java.util.ArrayList;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * @author harisucici
 * @date 2018/1/27 0027
 */

public class HomeMeFragment extends BaseFragment {
    int a = 50;
    int b = 50;
    @Nullable
    @BindView(R.id.fragment_me_num1)
    TextView fragmentMeNum1;
    @Nullable
    @BindView(R.id.fragment_me_num2)
    TextView fragmentMeNum2;
    @Nullable
    @BindView(R.id.fragment_me_head)
    RoundImageView fragmentMeHead;
    @Nullable
    @BindView(R.id.fragment_me_name)
    TextView fragmentMeName;
    @Nullable
    @BindView(R.id.fragment_me_phone)
    TextView fragmentMePhone;
    Unbinder unbinder;

    @Override
    public void responseError(int code, String msg) {
//        showShortToast(msg);

    }

    @Override
    public void requestFailure(Throwable t) {

    }

    @Override
    protected int setViewId() {
        return R.layout.fragment_me;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void doOnDestroyView() {

    }

    @Override
    protected void doOnResume() {

    }

    @Override
    protected void doOnVisible() {
        if (fragmentMeNum1 == null || fragmentMeNum2 == null) {
            return;
        }

        NumAnim.startAnim(fragmentMeNum1, a);
        NumAnim.startAnim(fragmentMeNum2, b);


        // 解析号型
//        ArrayList<String> dataList = Utils.jsa2list1(SpHelper.getInstance().getListltrule());
//        ArrayList<ListLtRuleBean> listLtRuleBeans = new ArrayList<>(2);
//        for (String s : dataList) {
//            listLtRuleBeans.add(new Gson().fromJson(s, ListLtRuleBean.class));
//        }

    }

    @Override
    protected void doOnInvisible() {

    }

    @Override
    protected void doOnSaveInstanceState() {

    }


    @OnClick(R.id.fragment_me_history)
    public void onFragmentMeHistoryClicked() {
        ArrayList<Map<String, Object>> batchList = SpHelper.getInstance().getBatchList();
        if (batchList.size() == 0) {
            showShortToast("没有数据,不必上传");
            return;
        }
//        for (Map<String, Object> batch : batchList) {
//            Map<String, Object> body = new HashMap<>(2);
//            body.put("batno", batch.get("batno"));
//            body.put("title", batch.get("title"));
//            body.put("maleID", batch.get("maleID"));
//            body.put("femaleID", batch.get("femaleID"));
//            // 更改人员在线/离线状态标识
//            ArrayList<PersonListBean> personListTemp = SpHelper.getInstance().getPersonList((String) batch.get("batno"));
//            ArrayList<PersonListBean> personList = new ArrayList<>();
//            if (personListTemp != null) {
//                for (PersonListBean personListBean : personListTemp) {
//                    personListBean.setOnline(Constant.ONLINE);
//                    personList.add(personListBean);
//                }
//            }
//            SpHelper.getInstance().setPersonList((String) batch.get("batno"), personList);
//            //上传新的标识
//            body.put("ltBatPersonDOLst", personList);
//            homeMePresenter.toSaveoneall(body);
//
//
//        }


    }

    @OnClick(R.id.fragment_me_pass)
    public void onFragmentMePassClicked() {
    }

    @OnClick(R.id.fragment_me_update)
    public void onFragmentMeUpdateClicked() {
        showShortToast("当前版本" + BuildConfig.VERSION_NAME);
    }

    @OnClick(R.id.fragment_me_us)
    public void onFragmentMeUsClicked() {
        showShortToast("际华3502");
    }

    @OnClick(R.id.fragment_me)
    public void onFragmentMeClicked() {
        Intent intent = new Intent(mContext, HomeMeActivity.class);
        if (Build.VERSION.SDK_INT > 20) {
            startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(getActivity(), fragmentMeHead, "img_me").toBundle());
        } else {
            startActivity(intent);
        }
    }


}
